// html 模板指定 使用commonjs因为用后端运行环境node
const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path");
const basePath = __dirname;

module.exports = {
  context: path.join(basePath, "src"),
  resolve: {
    extensions: [".js", ".ts", ".tsx"],
    alias: {
        "@": path.resolve(__dirname, "src"),
        "~": path.resolve(__dirname, "src/assets"),
      },
  },
  entry: {
    app: ["./main.tsx"],
  },
  output: {
    filename: "[name].[chunkhash].js",
  },
  mode:"development",
  devServer: {
    hot: true,
    open:true,// 自动打开
    port:1314
  },
  module: {
    rules: [
      {
        test: /\.tsx?$/, // 匹配以ts或tsx为后缀的0个或1个
        exclude: /node_modules/, // 排除
        loader: "babel-loader",
      },
      {
        test:/\.css$/,
        exclude:/node_modules/,
        use:[
            {
                loader:"style-loader"
            },
            {
                loader:"css-loader"
            }
        ]
      }
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      filename: "index.html",
      template: "index.html",
    }),
  ],
};
